/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.gyc.exceptionhomework;
/*
public static void main(String[] args) {
    Tank[] tanks = new Tank[5];
    Random random = new Random();
    for (int i = 0; i < tanks.length; i++) {
        tanks[i]=new Tank("坦克"+i,30+(int)(30*Math.random()));
    }
    for (int i = 0; i <tanks.length ; i++) {
        System.out.print(tanks[i]+" ");
    }

    for (int i = 0; i < tanks.length-1; i++) {

        for (int j = i; j < tanks.length; j++) {
            Tank tank=null;
            int n = tanks[i].compareTo(tanks[j]);
            if (n>0) {
                tank=tanks[i];
                tanks[i] = tanks[j];
                tanks[j]=tank;
            }
        }
    }
    System.out.println();
    System.out.println("排序后：");
    for (int i = 0; i <tanks.length ; i++) {
        System.out.print(tanks[i]+" ");
    }
}

 */
public class CircleWithRadiusException {
  /** The radius of the circle */
  private double radius;

  /** The number of the objects created */
  private static int numberOfObjects = 0;

  /** Construct a circle with radius 1 */
  public CircleWithRadiusException() {
    this(1.0);
  }

  /** Construct a circle with a specified radius */
  public CircleWithRadiusException(double newRadius) {
    try {
      setRadius(newRadius);
      numberOfObjects++;
    }
    catch (InvalidRadiusException ex) {
      ex.printStackTrace();
    }
  }

  /** Return radius */
  public double getRadius() {
    return radius;
  }

  /** Set a new radius */
  public void setRadius(double newRadius)
      throws InvalidRadiusException {
    if (newRadius >= 0)
      radius =  newRadius;
    else
      throw new InvalidRadiusException(newRadius);
  }

  /** Return numberOfObjects */
  public static int getNumberOfObjects() {
    return numberOfObjects;
  }

  /** Return the area of this circle */
  public double findArea() {
    return radius * radius * 3.14159;
  }
}